package com.yihu.wlyy.web.common.data;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.wlyy.entity.Disease;
import com.yihu.wlyy.service.common.data.DataService;
import com.yihu.wlyy.web.BaseController;

@RequestMapping(value = "/common/data")
@Controller
public class DataController extends BaseController {

	@Autowired
	private DataService dataService;

	@RequestMapping(value = "diseases")
	@ResponseBody
	public String diseases() {
		try {
			JSONArray array = new JSONArray();
			List<Disease> list = dataService.findAllDisease();
			for (Disease temp : list) {
				if (temp == null) {
					continue;
				}
				JSONObject json = new JSONObject();
				json.put("code", temp.getCode());
				json.put("name", temp.getName());
				array.put(json);
			}
			return write(200, "获取疾病成功！", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取疾病失败！");
		}
	}

	@RequestMapping(value = "diseases_community")
	@ResponseBody
	public String diseasesCommunity() {
		try {
			JSONArray array = new JSONArray();
			List<Disease> list = dataService.findAllDisease();
			for (Disease temp : list) {
				if (temp == null) {
					continue;
				}
				JSONObject json = new JSONObject();
				json.put("code", temp.getCode());
				json.put("name", temp.getName() + "社区");
				array.put(json);
			}
			return write(200, "获取疾病社区成功！", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取疾病社区失败！");
		}
	}

}
